package com.wx.tgp.designpattern.observerPattern.observer;

/**
 * 具体观察者，实现抽象观察者角色所要求的更新接口，已是本身
 * 状态与主题状态对调
 */
public class ConcreteObserver extends Observer{

    private String subjectState;
    private String name;
    private ConcreteSubject subject;

    public ConcreteObserver(ConcreteSubject subject,String name){
        this.subject = subject;
        this.name = name;
    }
    @Override
    public void update() {
        subjectState = subject.getSubjectState();
        System.out.println("The observer's state of" + name + " is " + subjectState);
    }

    public String getSubjectState() {
        return subjectState;
    }

    public void setSubjectState(String subjectState) {
        this.subjectState = subjectState;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ConcreteSubject getSubject() {
        return subject;
    }

    public void setSubject(ConcreteSubject subject) {
        this.subject = subject;
    }
}
